import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';

const routes: RouteRecordRaw[] = [
	{
		path: '/login',
		name: 'login',
		component: () => import('@/views/login.vue'),
	},

	{
		path: '/',
		name: 'layout',
		redirect: '/home',
		component: () => import('@/layouts/default.vue'),
		children: [
			{
				path: '',
				name: 'home',
				component: () => import('@/views/home/index.vue'),
			},
		],
	},
	{
		path: '/:pathMatch(.*)*',
		name: '*',
		component: () => import('@/views/404.vue'),
	},
	{
		path: '/vant-comonponents',
		name: 'vant-comonponents',
		component: () => import('@/views/vant-comonponents/index.vue'),
	},
];

const router = createRouter({ history: createWebHashHistory(), routes });
// 路由前置守卫
router.beforeEach((_to, _from, next) => next());
router.onError((error) => {
	console.error('路由错误:', error);
}); // 在这里处理路由错误

export { routes };
export default router;
